//package com.xsj.config;
//
//import com.fasterxml.jackson.databind.ObjectMapper;
//import org.apache.rocketmq.client.producer.DefaultMQProducer;
//import org.apache.rocketmq.spring.core.RocketMQTemplate;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.messaging.converter.CompositeMessageConverter;
//import org.springframework.messaging.converter.MappingJackson2MessageConverter;
//import org.springframework.messaging.converter.MessageConverter;
//
//import java.util.ArrayList;
//import java.util.List;
//
//@Configuration
//public class RocketMQConfig {
//
//    @Value("${rocketmq.name-server}")
//    private String nameServer;
//
//    @Value("${rocketmq.producer.group}")
//    private String producerGroup;
//
//    @Bean
//    public RocketMQTemplate rocketMQTemplate(ObjectMapper objectMapper) {
//        RocketMQTemplate rocketMQTemplate = new RocketMQTemplate();
//
//        DefaultMQProducer producer = new DefaultMQProducer(producerGroup);
//        producer.setNamesrvAddr(nameServer);
//        rocketMQTemplate.setProducer(producer);
//
//        // 使用 Spring Boot 的 ObjectMapper 进行 JSON 转换
//        MappingJackson2MessageConverter jackson2MessageConverter = new MappingJackson2MessageConverter();
//        jackson2MessageConverter.setObjectMapper(objectMapper);
//
//        List<MessageConverter> converters = new ArrayList<>();
//        converters.add(jackson2MessageConverter);
//
//        rocketMQTemplate.setMessageConverter(new CompositeMessageConverter(converters));
//
//        return rocketMQTemplate;
//    }
//}